﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Collections;
using System.Threading;
using System.Windows.Forms;

namespace MyFreecell
{
    public partial class FrmMain : Form
    {
        //游戏对象说明
        private Game game;
        public FrmMain()
        {
            InitializeComponent();
            SetStyle(ControlStyles.UserPaint |
         ControlStyles.AllPaintingInWmPaint |
         ControlStyles.DoubleBuffer, true);
            CheckForIllegalCrossThreadCalls = false;
        }

        Control m;//存储menuStrip1，在新游戏清空内容时将其再次添加
        Control s;//存储statusStrip1
        int mouseX;//鼠标横坐标
        private void FrmMain_Load(object sender, EventArgs e)
        {
            //初始化游戏类
            game = new Game();
            game.ChuShiCanShu(this.Size);
            m = MenuStrip;
            s = NoticeStrip;
            SurplusNumberLabel.Text = game.ShengYuPaiNum.ToString() + " 张";
            新游戏NToolStripMenuItem.Enabled = false;//新游戏的按钮不能按
        }

        /// <summary>
        /// 开始游戏
        /// </summary>
        public void StartGame()
        {
            //game.testPaiShun();//先用顺序牌测试
            game.XiPai();
            game.FaPai(this);
        }

        private void FrmMain_Paint(object sender, PaintEventArgs e)
        {
            
            if (game!=null)//游戏已经初始化了
            {
                game.Draw(e.Graphics, this.Size,this);
            }
        }

        private void FrmMain_Resize(object sender, EventArgs e)
        {
        }

        private void FrmMain_MouseEnter(object sender, EventArgs e)
        {
            game.Destination();
        }

        /// <summary>
        /// 开始游戏按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 开始游戏SToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StartGame();
            开始游戏SToolStripMenuItem.Enabled = false;
            新游戏NToolStripMenuItem.Enabled = true;
        }

        /// <summary>
        /// 开始一局新游戏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 新游戏NToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Control c in this.Controls)
            {
                this.Controls.Clear();
            }
            this.Controls.Add(m);
            this.Controls.Add(s);
            game.ChuShiCanShu(this.Size);
            StartGame();
        }

        private void FrmMain_DragOver(object sender, DragEventArgs e)
        {
            game.Drag(sender, e, this);
        }

        private void FrmMain_MouseMove(object sender, MouseEventArgs e)
        {
            mouseX = e.Location.X;
            if (mouseX < this.Width / 2)
            {
                game.KingLeft();
            }
            if (mouseX > this.Width/2)
            {
                game.KingRight();
            }
        }

        private void 关于我ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmAboutme frm = new FrmAboutme();
            frm.ShowDialog();
        }
    }
}
